#include<iostream>
#include<vector>
#include<unordered_map>
#include<cmath>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> v(n);
        unordered_map<double, int> freq_map;
        int s = 0;
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
            double feature = log2(v[i]) - v[i];
            s += freq_map[feature];
            freq_map[feature]++;
        }
        cout << s << endl;
    }
    return 0;
}